package com.ianmoone.JZOF;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

public class XCTest3 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int end = 0;
		in.nextLine();
		int[] a = new int[n];
		List<Integer> list = new LinkedList<>();
		Queue<Integer> queue = new LinkedList<>();
		HashMap<Integer, Integer> map = new HashMap<>();
		while (in.hasNextLine()) {
			String string = in.nextLine();
			String[] split = string.split(" ");
			String func = split[0];
			if (func.equals("p")) {
				if (map.size() == n) {
					map.remove(end);
				}
				int key = Integer.valueOf(split[1]);
				int value = Integer.valueOf(split[2]);
				map.put(key, value);
				end = key;
				
			}else if (func.equals("g")) {
				int key = Integer.valueOf(split[1]);
				if (map.get(key) == null) {
					System.out.println("-1");
				}else{
					System.out.println(map.get(key));
				}
				
			}
		}
	}
}
